import { memo, useEffect, useMemo, useRef, useState } from 'react'
import * as echarts from 'echarts'
import classNames from 'classnames'
import { isObject } from '@multi-kit/inspect'
import { SwitchButton } from '@/components'
import { Flex, Radio, Input, Button, Form, InputNumber } from 'antd';
import { setDAC } from '@/api/common.api';
import { scaleObjectValues } from '@/utils/utility';

export interface Props {
  state: unknown
}

function DACConfig<Props>(props: Props) {
  const { state } = props


  const [aForm] = Form.useForm();
  const [bForm] = Form.useForm();

  const saveAction = (id, values) => {

    setDAC({ id, ...scaleObjectValues(values) })
  }



  return (
    <div className="grid grid-cols-6  ">
      <div className="col-span-2 p-2 flex text-center border border-slate-700 flex items-center justify-center">电机A</div>
      <div className="col-span-4 p-2 text-center border border-slate-700">
        <Form
          layout="inline"
          form={aForm}
          onFinish={(values) => saveAction(0, values)}
          className=' flex items-center justify-center gap-2'
        >

          <Form.Item name="dac" className='flex-1 m-0'>
            <InputNumber className='w-full' placeholder="DAC参数" min={0.0} max={3.3} step={0.1} />
          </Form.Item>
          <Form.Item className='m-0'>
            <Button type="primary" htmlType="submit" >设置</Button>
          </Form.Item>
        </Form>
      </div>
      <div className="col-span-2 p-2 flex text-center border border-slate-700  rounded-bl-md flex items-center justify-center">电机B</div>
      <div className="col-span-4 p-2 text-center border border-slate-700  rounded-br-md">
        <Form
          layout="inline"
          form={bForm}
          onFinish={(values) => saveAction(1, values)}
          className=' flex items-center justify-center gap-2'
        >

          <Form.Item name="dac" className='flex-1 m-0'>
            <InputNumber className='w-full' placeholder="DAC参数" min={0.0} max={3.3} step={0.1} />
          </Form.Item>
          <Form.Item className='m-0'>
            <Button type="primary" htmlType="submit" >设置</Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  )
}

export default memo(DACConfig)
